﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MagicFight
{
    public class ManaDrain : Magic
    {
        int radius = Def.ManaDrainDef.Radius;
        int manaDrain = Def.ManaDrainDef.ManaDrain;

        public ManaDrain(Character caster)
            : base(caster, Def.ManaDrainDef.N)
        {
        }

        public override void Effect(GameTime gameTime)
        {
            alive = false;
            ps.effectsManager.Add(new DrainAura(caster.position));
            foreach (GameObject obj in ps.gameObjects)
            {
                if (obj == null) continue;
                if (!obj.alive) continue;
                if (!(obj is Character)) continue;
                if (obj == caster) continue;
                if (Vector2.Distance(caster.position, obj.position) < radius)
                {
                    Character charTarget = obj as Character;
                    if (manaDrain > charTarget.MP) manaDrain = charTarget.MP;
                    charTarget.ConsumeMana(manaDrain);
                    int gained = caster.GainMP(manaDrain);
                    ps.effectsManager.Add(new FloatingText(charTarget.position, "-" + manaDrain + " MP", Color.Blue));
                    ps.effectsManager.Add(new FloatingText(caster.position, "+" + gained + " MP", Color.Blue));
                    Log.Add(caster.name+" drenou "+ manaDrain+ " MP de "+charTarget.name);
                }
            }

        }
    }
}
